<template>
  <view class="address-panel">
    <!-- 关闭按钮 -->
    <!-- <text class="close icon-close"></text> -->
    <!-- 标题 -->
    <view class="title">绑定地址</view>
    <!-- 内容 -->
    <view class="content">
      <input v-model="address" class="input" type="text" placeholder="绑定地址" />
      <uni-data-select
        v-model="value"
        :localdata="trashcans"
        @change="change"
        :clear="false"
      ></uni-data-select>
    </view>
    <view class="footer">
      <view class="button primary" @click="band"> 绑定 </view>
    </view>
  </view>
</template>
<script>
import { bindtrashcan, getalltrashcans } from '@/services/login'
export default {
  props: {
    wxUser: String,
    trashcans: Array,
  },
  data() {
    return {
      value: 0,
      range: [
        { value: 0, text: '篮球' },
        { value: 1, text: '足球' },
        { value: 2, text: '游泳' },
      ],
      form: {
        address: '',
        trashcan_id: '',
      },
      User: '',
      bianhaolist: [],
    }
  },
  onShow() {
    console.log('111111111111111111111111')
  },
  // onShow() {
  //     this.wxUser = uni.getStorageSync("wxuser")
  //     console.log(this.wxUser,' this.wxUser');
  // },
  methods: {
    openPopup() {
      this.$refs.popup.open('top')
    },
    async band() {
      const res = await bindtrashcan({
        token: this.wxUser.token,
        trashcan_id: Number(this.value),
        address: this.address,
      })
      if (res.success) {
        uni.showToast({
          title: '添加成功',
        })
      }
      setTimeout(()=>{
        this.$emit('close')
      },500)
    },
  },
}
</script>
<style lang="scss">
.input {
  width: 100%;
  height: 80rpx;
  font-size: 28rpx;
  border-radius: 72rpx;
  border: 1px solid #ddd;
  padding-left: 30rpx;
  margin-bottom: 20rpx;
}
.address-panel {
  padding: 0 30rpx;
  border-radius: 10rpx 10rpx 0 0;
  position: relative;
  background-color: #fff;
}

.title {
  line-height: 1;
  padding: 40rpx 0;
  text-align: center;
  font-size: 32rpx;
  font-weight: normal;
  border-bottom: 1rpx solid #ddd;
  color: #444;
}

.close {
  position: absolute;
  right: 24rpx;
  top: 24rpx;
}

.content {
  min-height: 300rpx;
  max-height: 540rpx;
  overflow: auto;
  padding: 20rpx;
  .item {
    padding: 30rpx 50rpx 30rpx 60rpx;
    background-size: 40rpx;
    background-repeat: no-repeat;
    background-position: 0 center;
    background-image: url(https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/images/locate.png);
    position: relative;
  }
  .icon {
    color: #999;
    font-size: 40rpx;
    transform: translateY(-50%);
    position: absolute;
    top: 50%;
    right: 0;
  }
  .icon-checked {
    color: #27ba9b;
  }
  .icon-ring {
    color: #444;
  }
  .user {
    font-size: 28rpx;
    color: #444;
    font-weight: 500;
  }
  .address {
    font-size: 26rpx;
    color: #666;
  }
}

.footer {
  display: flex;
  justify-content: space-between;
  padding: 20rpx 0 40rpx;
  font-size: 28rpx;
  color: #444;

  .button {
    flex: 1;
    height: 72rpx;
    text-align: center;
    line-height: 72rpx;
    margin: 0 20rpx;
    color: #fff;
    border-radius: 72rpx;
  }

  .primary {
    color: #fff;
    background-color: #27ba9b;
  }

  .secondary {
    background-color: #ffa868;
  }
}
</style>
